package com.alibaba.nacos;

import com.alibaba.nacos.console.config.NacosConfig;
import com.alibaba.nacos.sys.filter.NacosTypeExcludeFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter;
import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableScheduling;

@ComponentScan(basePackages = "com.alibaba.nacos", excludeFilters = {
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {NacosTypeExcludeFilter.class}),
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class}),
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class})})
@ServletComponentScan
@EnableScheduling
public class Nacos {

    /**
     * 应用程序启动入口
     *
     * @param args 参数
     */
    public static void main(String[] args) {
        // 启动模式：true-单机模式，false-集群模式
        // 特别说明如下：
        // 1、集群模式下需要配置文件支持
        // 2、分别在所有 nacos 目录下创建 conf/cluster.conf 配置文件用于编写集群IP端口,详情请查阅官方文档
        System.setProperty(NacosConfig.NACOS_STANDALONE_MODE, "true");
        // 开启鉴权认证：true-开启登录认证，false-关闭登录认证
        System.setProperty(NacosConfig.NACOS_AUTH_ENABLED, "true");
        // 权限缓存开关,开启后权限缓存的更新默认有15秒的延迟,默认false
        System.setProperty(NacosConfig.NACOS_AUTH_CACHE_ENABLED, "true");
        // 开启日志：true-开启日志，false-关闭日志
        System.setProperty(NacosConfig.NACOS_LOG_ENABLED, "false");
        // 日志目录，注意Docker容器部署时需要设置挂载目录映射出去
        System.setProperty(NacosConfig.NACOS_LOG_BASEDIR, "logs");
        // 设置Nacos访问上下文前缀,默认nacos
        System.setProperty(NacosConfig.NACOS_CONTEXT_PATH, "/nacos");
        // 启动应用
        SpringApplication.run(Nacos.class, args);
    }

}